import { loadEnv, defineConfig } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
import path from 'path';
// import viteCompression from 'vite-plugin-compression';
import uniReadPagesV3Plugin from './ulm/router/utils/uni-read-pages-v3';
import AutoImport from 'unplugin-auto-import/vite'

const define = {}
if (!["mp-weixin", "h5", "web"].includes(process.env.UNI_PLATFORM)) {
	define['global'] = null
	define['wx'] = 'uni'
}
// https://vitejs.dev/config/
export default (command, mode) => {
	const env = loadEnv(mode, __dirname, 'LM_');

	return {
		envPrefix: "LM_",
		plugins: [
			uni(),
			// viteCompression({
			// 	verbose: false
			// }),
			uniReadPagesV3Plugin({
				pagesJsonDir: path.resolve(__dirname, './pages.json'),
				includes: ['path', 'aliasPath', 'name', 'meta'],
			}),
			AutoImport({
				imports: ['vue', 'uni-app'],
				dts: 'types/auto-import.d.ts',
				vueTemplate: true
			})
		],
		define,
		server: {
			host: true,
			// open: true,
			port: env.LM_DEV_PORT,
			hmr: {
				overlay: true,
			},
		},
	};
};
